﻿{include file="public/header"/}
</head>
<body>
<div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                    <button data-type="add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>新增广告位置</button>
                    <button data-type="batch_del" data-url="{:url('/adposition/batch_del')}" class="layui-btn layui-btn-danger icon-btn">
                    <i class="layui-icon"></i>批量删除</button>
                    </div>
                </div>
            </div>
            <table id="tablelist" lay-filter="tablelist"></table>
        </div>
    </div>
</div>
<script type="text/html" id="tableBarUser">
    <a class="layui-btn layui-btn-primary layui-btn-sm" href="{:url('/adposition/ad_index')}?id={{d.id}}">内容列表</a>
    <a class="layui-btn layui-btn-primary layui-btn-sm" data-id="{{d.id}}" data-type="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" data-url="{:url('/adposition/del')}" data-id="{{d.id}}" data-type="del">删除</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'table'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;

        // 渲染表格
        var insTb = table.render({
            elem: '#tablelist',
            url: "{:url('/adposition/index')}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type:'checkbox'},
                {field:'id',title:'ID',width:60},
                {field: 'title', title: '广告名称'},
                {field: 'content', title: '广告描述'},
                {field: 'add_time', title: '添加时间',width: 180,align: 'center'},
                {align: 'center', toolbar: '#tableBarUser', title: '操作', width:300}
            ]]
        });

        $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });

        //触发事件
        var active = {
            add: function(){
                layer.open({
                    type: 2,
                    title: '新增广告位置',
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: '{:url("/adposition/add")}'
                });
            },
            edit: function(){
                var obj = this;
                var id = $(obj).attr('data-id');
                layer.open({
                    type: 2,
                    title: '编辑广告位置',
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: '{:url("/adposition/edit")}?id='+id
                });
            },
            pcftag: function(){
               var obj = this;
               var id = $(obj).attr('data-id');
               resetPsw(id, 1);
            },
            del: function(){
                delfun(this);
            },
            batch_del: function(){
                var checkRows = table.checkStatus('tablelist');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.id;
                });
                batch_del(this, ids);
            }
        };
        
    });
</script>
</body>
</html>